package com.ruoyi.web.controller.glue;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.GlueBanner;
import com.ruoyi.system.service.IGlueBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 轮播图
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@RestController
@RequestMapping("/system/banner")
public class GlueBannerController extends BaseController
{
    @Autowired
    private IGlueBannerService glueBannerService;

    /**
     * 查询轮播图列表
     * @return {@link GlueBanner}
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlueBanner glueBanner)
    {
        startPage();
        List<GlueBanner> list = glueBannerService.selectGlueBannerList(glueBanner);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:export')")
    @Log(title = "轮播图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GlueBanner glueBanner)
    {
        List<GlueBanner> list = glueBannerService.selectGlueBannerList(glueBanner);
        ExcelUtil<GlueBanner> util = new ExcelUtil<GlueBanner>(GlueBanner.class);
        util.exportExcel(response, list, "轮播图数据");
    }

    /**
     * 获取轮播图详细信息
     * @return {@link GlueBanner}
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(glueBannerService.selectGlueBannerById(id));
    }

    /**
     * 新增轮播图
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:add')")
    @Log(title = "轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GlueBanner glueBanner)
    {
        return toAjax(glueBannerService.insertGlueBanner(glueBanner));
    }

    /**
     * 修改轮播图
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:edit')")
    @Log(title = "轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GlueBanner glueBanner)
    {
        return toAjax(glueBannerService.updateGlueBanner(glueBanner));
    }

    /**
     * 删除轮播图
     */
    //@PreAuthorize("@ss.hasPermi('system:banner:remove')")
    @Log(title = "轮播图", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(glueBannerService.deleteGlueBannerByIds(ids));
    }
}
